//
//  ChallengeCell.m
//  兼职页面
//
//  Created by kuiyuan liang on 2021/5/29.
//

#import "ChallengeCell.h"
#import "CommonUtil.h"
#import "ChallengeAlert.h"

@interface ChallengeCell()
@property (strong, nonatomic) UIView * whiteView;
@property (strong, nonatomic) UILabel * typeLabel;
@property (strong, nonatomic) UILabel * typeValueLabel;

@property (strong, nonatomic) UILabel * startLabel;
@property (strong, nonatomic) UILabel * startValueLabel;

@property (strong, nonatomic) UILabel * mubiaoLabel;
@property (strong, nonatomic) UILabel * mubiaoValueLabel;

@property (strong, nonatomic) UILabel * currentLabel;
@property (strong, nonatomic) UILabel * currentValueLabel;

@property (strong, nonatomic) UIButton * joinBtn;

@property (strong, nonatomic) UIButton * giveupBtn;
@property (strong, nonatomic) UIButton * haveinBtn;
@property (strong, nonatomic) UIButton * publishBtn;
@end

@implementation ChallengeCell
-(instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        self.backgroundColor = [UIColor clearColor];
        self.selectionStyle = UITableViewCellSelectionStyleNone;
        [self.contentView addSubview:self.whiteView];
        [self.whiteView addSubview:self.typeLabel];
        [self.whiteView addSubview:self.typeValueLabel];
        
        [self.whiteView addSubview:self.startLabel];
        [self.whiteView addSubview:self.startValueLabel];
        
        [self.whiteView addSubview:self.mubiaoLabel];
        [self.whiteView addSubview:self.mubiaoValueLabel];
        
        [self.whiteView addSubview:self.currentLabel];
        [self.whiteView addSubview:self.currentValueLabel];
        
        [self.whiteView addSubview:self.joinBtn];
        [self.whiteView addSubview:self.giveupBtn];
        [self.whiteView addSubview:self.haveinBtn];
        [self.whiteView addSubview:self.publishBtn];
    }
    return self;
}

-(void)layoutSubviews{
    [super layoutSubviews];
    self.whiteView.width = self.width;
    self.joinBtn.width = self.whiteView.width - AD(20);
    self.giveupBtn.width = (self.whiteView.width - AD(40))/3;
    self.haveinBtn.width = self.giveupBtn.width;
    self.publishBtn.width = self.giveupBtn.width;
    
    self.giveupBtn.left = AD(10);
    self.haveinBtn.left = self.giveupBtn.right + AD(10);
    self.publishBtn.left = self.haveinBtn.right + AD(10);
}

-(void)setModel:(ChallengeModel *)model{
    _model = model;
    
    if (model.moreBtn) {
        self.joinBtn.hidden = YES;
        self.giveupBtn.hidden = false;
        self.haveinBtn.hidden = false;
        self.publishBtn.hidden = false;
    }else{
        self.joinBtn.hidden = false;
        self.giveupBtn.hidden = YES;
        self.haveinBtn.hidden = YES;
        self.publishBtn.hidden = YES;
    }
}

- (void)btnClick:(UIButton *)sender{
    if (self.block) {
        self.block(sender.titleLabel.text);
    }

}


-(UIView *)whiteView{
    if (!_whiteView) {
        _whiteView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 0, AD(190))];
        _whiteView.backgroundColor = [UIColor whiteColor];
        _whiteView.layer.cornerRadius= AD(5);
    }
    return _whiteView;
}

-(UILabel *)typeLabel{
    if (!_typeLabel) {
        _typeLabel = [[UILabel alloc] initWithFrame:CGRectMake(AD(10), AD(10), 0, AD(30))];
        _typeLabel.text = @"类型:";
        _typeLabel.textColor = [UIColor blackColor];
        _typeLabel.font = [UIFont boldSystemFontOfSize:AD(15)];
        _typeLabel.width = [CommonUtil countWidth:_typeLabel.text font:_typeLabel.font height:_typeLabel.height];
    }
    return _typeLabel;
}
-(UILabel *)typeValueLabel{
    if (!_typeValueLabel) {
        _typeValueLabel = [[UILabel alloc] initWithFrame:CGRectMake(_typeLabel.right + AD(3), AD(10), AD(200), AD(30))];
        _typeValueLabel.text = @"三肖";
        _typeValueLabel.textColor = RGB(124.0, 124.0, 124.0);
        _typeValueLabel.font = [UIFont boldSystemFontOfSize:AD(15)];
    }
    return _typeValueLabel;
}

-(UILabel *)startLabel{
    if (!_startLabel) {
        _startLabel = [[UILabel alloc] initWithFrame:CGRectMake(AD(10), _typeLabel.bottom, 0, AD(30))];
        _startLabel.text = @"起始期数:";
        _startLabel.textColor = [UIColor blackColor];
        _startLabel.font = [UIFont boldSystemFontOfSize:AD(15)];
        _startLabel.width = [CommonUtil countWidth:_startLabel.text font:_startLabel.font height:_startLabel.height];
    }
    return _startLabel;
}
-(UILabel *)startValueLabel{
    if (!_startValueLabel) {
        _startValueLabel = [[UILabel alloc] initWithFrame:CGRectMake(_startLabel.right + AD(3), _typeLabel.bottom, AD(200), AD(30))];
        _startValueLabel.text = @"20211037期";
        _startValueLabel.textColor = RGB(124.0, 124.0, 124.0);
        _startValueLabel.font = [UIFont boldSystemFontOfSize:AD(15)];
    }
    return _startValueLabel;
}

-(UILabel *)mubiaoLabel{
    if (!_mubiaoLabel) {
        _mubiaoLabel = [[UILabel alloc] initWithFrame:CGRectMake(AD(10), _startLabel.bottom, 0, AD(30))];
        _mubiaoLabel.text = @"目标:";
        _mubiaoLabel.textColor = [UIColor blackColor];
        _mubiaoLabel.font = [UIFont boldSystemFontOfSize:AD(15)];
        _mubiaoLabel.width = [CommonUtil countWidth:_mubiaoLabel.text font:_mubiaoLabel.font height:_mubiaoLabel.height];
    }
    return _mubiaoLabel;
}
-(UILabel *)mubiaoValueLabel{
    if (!_mubiaoValueLabel) {
        _mubiaoValueLabel = [[UILabel alloc] initWithFrame:CGRectMake(_mubiaoLabel.right + AD(3), _startLabel.bottom, AD(200), AD(30))];
        _mubiaoValueLabel.text = @"0 对 0 以 上";
        _mubiaoValueLabel.textColor = RGB(124.0, 124.0, 124.0);
        _mubiaoValueLabel.font = [UIFont boldSystemFontOfSize:AD(15)];
    }
    return _mubiaoValueLabel;
}

-(UILabel *)currentLabel{
    if (!_currentLabel) {
        _currentLabel = [[UILabel alloc] initWithFrame:CGRectMake(AD(10), _mubiaoLabel.bottom, 0, AD(30))];
        _currentLabel.text = @"当前:";
        _currentLabel.textColor = [UIColor blackColor];
        _currentLabel.font = [UIFont boldSystemFontOfSize:AD(15)];
        _currentLabel.width = [CommonUtil countWidth:_currentLabel.text font:_currentLabel.font height:_currentLabel.height];
    }
    return _currentLabel;
}
-(UILabel *)currentValueLabel{
    if (!_currentValueLabel) {
        _currentValueLabel = [[UILabel alloc] initWithFrame:CGRectMake(_currentLabel.right + AD(3), _mubiaoLabel.bottom, AD(200), AD(30))];
        _currentValueLabel.text = @"0 对 0";
        _currentValueLabel.textColor = RGB(124.0, 124.0, 124.0);
        _currentValueLabel.font = [UIFont boldSystemFontOfSize:AD(15)];
    }
    return _currentValueLabel;
}

-(UIButton *)joinBtn{
    if (!_joinBtn) {
        _joinBtn = [UIButton buttonWithType:UIButtonTypeCustom];
        [_joinBtn setTitle:@"参加" forState:UIControlStateNormal];
        [_joinBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
        _joinBtn.titleLabel.font = [UIFont boldSystemFontOfSize:AD(15)];
        _joinBtn.layer.cornerRadius = AD(5);
        _joinBtn.backgroundColor = RGB(236.0, 92.0, 77.0);
        _joinBtn.frame = CGRectMake(AD(10), _currentLabel.bottom + AD(5), 0, AD(40));
        [_joinBtn addTarget:self action:@selector(btnClick:) forControlEvents:UIControlEventTouchUpInside];
    }
    return _joinBtn;
}

-(UIButton *)giveupBtn{
    if (!_giveupBtn) {
        _giveupBtn = [UIButton buttonWithType:UIButtonTypeCustom];
        [_giveupBtn setTitle:@"放弃" forState:UIControlStateNormal];
        [_giveupBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
        _giveupBtn.titleLabel.font = [UIFont boldSystemFontOfSize:AD(15)];
        _giveupBtn.layer.cornerRadius = AD(5);
        _giveupBtn.backgroundColor = RGB(182.0, 182.0, 182.0);
        _giveupBtn.frame = CGRectMake(0, _currentLabel.bottom + AD(5), 0, AD(40));
        [_giveupBtn addTarget:self action:@selector(btnClick:) forControlEvents:UIControlEventTouchUpInside];
    }
    return _giveupBtn;
}

-(UIButton *)haveinBtn{
    if (!_haveinBtn) {
        _haveinBtn = [UIButton buttonWithType:UIButtonTypeCustom];
        [_haveinBtn setTitle:@"进行中" forState:UIControlStateNormal];
        [_haveinBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
        _haveinBtn.titleLabel.font = [UIFont boldSystemFontOfSize:AD(15)];
        _haveinBtn.layer.cornerRadius = AD(5);
        _haveinBtn.backgroundColor = RGB(81.0, 172.0, 211.0);
        _haveinBtn.frame = CGRectMake(0, _currentLabel.bottom + AD(5), 0, AD(40));
        [_haveinBtn addTarget:self action:@selector(btnClick:) forControlEvents:UIControlEventTouchUpInside];
    }
    return _haveinBtn;
}

-(UIButton *)publishBtn{
    if (!_publishBtn) {
        _publishBtn = [UIButton buttonWithType:UIButtonTypeCustom];
        [_publishBtn setTitle:@"发表" forState:UIControlStateNormal];
        [_publishBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
        _publishBtn.titleLabel.font = [UIFont boldSystemFontOfSize:AD(15)];
        _publishBtn.layer.cornerRadius = AD(5);
        _publishBtn.backgroundColor = RGB(236.0, 92.0, 77.0);
        _publishBtn.frame = CGRectMake(0, _currentLabel.bottom + AD(5), 0, AD(40));
        [_publishBtn addTarget:self action:@selector(btnClick:) forControlEvents:UIControlEventTouchUpInside];
    }
    return _publishBtn;
}



@end
